package com.ucvisitorsapp.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.MenuItem;

import com.example.ucvisitorsapp.R;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.ucvisitorsapp.dao.BuildingDatabase;


public class LoadActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    	
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        //check if google play service is available
        GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext()); 
        
        
        final Intent dbIntent = new Intent(LoadActivity.this, BuildingDatabase.class);
        LoadActivity.this.startActivity(dbIntent);
        
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                final Intent mainIntent = new Intent(LoadActivity.this, SearchScreen.class);
                LoadActivity.this.startActivity(mainIntent);
                LoadActivity.this.finish();
            }
        }, 5000);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle item selection
        switch (item.getItemId()) {
            case R.id.search_menuitem:
            	Intent intent = new Intent(this, SearchScreen.class);
            	startActivity(intent);
            	finish();
                return true;
            case R.id.map_menuitem:
            	Intent mapIntent = new Intent(this, MapScreen.class);
            	startActivity(mapIntent);
            	finish();
            	return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }  
    
    @SuppressWarnings("unused")
	private void loadStep(){
    	//TODO:acquire GPS signal
    	
    	//TODO:check to see if user is in bounds
    	
    	//if within bounds start map activity
		Intent intent = new Intent(this, MapScreen.class);
		startActivity(intent);
		finish();
    }
}
